package com.plume.toolbox.plus;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.hnphqs.nemoapi.CloudV.changeVPe;
import com.hnphqs.nemoapi.CloudV.changeVPu;
import com.hnphqs.nemoapi.CloudV.listV;
import java.util.List;

public class CloudVActivity extends AppCompatActivity {
    
    public void 大牛大牛求你别逆向了(){}
    private String selectedItem;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cloud_v);
        
        EditText workIDText=findViewById(R.id.workID);
        EditText cloudVName=findViewById(R.id.cloudVName);
        EditText cloudVCID=findViewById(R.id.cloudVCVID);
        EditText cloudVCT=findViewById(R.id.cloudVCT);
        Spinner typeSpinner = findViewById(R.id.vTypeSpinner);

        String[] items = {"number", "string"};
        ArrayAdapter<String> adapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item,items); 
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        typeSpinner.setAdapter(adapter);
        
        typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // 记录当前选择的项
                selectedItem = (String) parent.getItemAtPosition(position);
            }

            @Override
             public void onNothingSelected(AdapterView<?> parent) {
            // 什么都不做
            }
        });
        
        Button checkV=findViewById(R.id.checkV);
        checkV.setOnClickListener(v->{
            Toast.makeText(this,"查询中...",Toast.LENGTH_SHORT).show();    
            listV client = new listV();
            client.connect(
                    workIDText.getText().toString(),
                    UserInfoSaver.loadToken(this),
                    cloudVName.getText().toString(),
                    findViewById(R.id.cloudVCVID),
                    this);    
        });
        
        Button changePu=findViewById(R.id.changePu);
        changePu.setOnClickListener(v->{
            Toast.makeText(this,"更改中...",Toast.LENGTH_SHORT).show();    
            changeVPu client = new changeVPu();
            client.connect(
                    workIDText.getText().toString(),
                    UserInfoSaver.loadToken(this),
                    cloudVCID.getText().toString(),
                    cloudVCT.getText().toString(),
                    selectedItem,
                    this);    
        });
        
        Button changePe=findViewById(R.id.changePe);
        changePe.setOnClickListener(v->{
            Toast.makeText(this,"更改中...",Toast.LENGTH_SHORT).show();    
            changeVPe client = new changeVPe();
            client.connect(
                    workIDText.getText().toString(),
                    UserInfoSaver.loadToken(this),
                    cloudVCID.getText().toString(),
                    cloudVCT.getText().toString(),
                    selectedItem,
                    this);    
        });
    }
}
